package com.shy.springframework.aop.framework.adapter;

import com.shy.springframework.aop.MethodBeforeAdvice;
import com.shy.springframework.beans.factory.annotation.Autowired;
import com.shy.springframework.stereotype.Component;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @author yzpang
 * @desc: 方法前置拦截器
 * @date: 2023/2/10 15:52
 */
@Component(value = "interceptor")
public class MethodBeforeAdviceInterceptor implements MethodInterceptor {
    @Autowired
    private MethodBeforeAdvice advice;

    public MethodBeforeAdviceInterceptor() {
    }

    public MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice) {
        this.advice = advice;
    }

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        this.advice.before(invocation.getMethod(), invocation.getArguments(), invocation.getThis());
        return invocation.proceed();
    }
}
